package com.shangke.springbootkkyp.conller;

import com.shangke.springbootkkyp.pojo.Admin;
import com.shangke.springbootkkyp.serview.AdminSerview;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/mailing")
@Api("用户地址管理")
public class AdminConller {
    @Autowired
    AdminSerview adminSerview;

    @PostMapping("/add")
    @ApiOperation("新增地址记录")
    public Integer adminAdd(@ApiParam("区县") @RequestParam("area")String area,@ApiParam("市") @RequestParam("city") String city,@ApiParam("详细地址") @RequestParam("detailaddress") String detailaddress,
                            @ApiParam("是否默认") @RequestParam("priority")String priority,@ApiParam("省份") @RequestParam("province") String province,@ApiParam("手机") @RequestParam("tel") String tel,
                            @ApiParam("收货人姓名") @RequestParam("username")String username,@ApiParam("授权码") @RequestParam("xxlSsoSessionid") String xxlSsoSessionid){
        return adminSerview.adminaAdd(new Admin(area,city,detailaddress,priority,province,tel,username,xxlSsoSessionid));
    }

    @PostMapping("/delete")
    @ApiOperation("删除地址记录")
    public boolean adminDelete(@ApiParam("收货地址编号") @RequestParam("id")Long id,@ApiParam("授权编码") @RequestParam("xxlSsoSessionid") String xxlSsoSessionid){
        return adminSerview.adminDelete(id,xxlSsoSessionid);
    }

    /**
     * 修改后面写，service层还要改写
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation("修改收货地址")
    public Boolean adminEdit(){
        if (1 == 1){
            return true;
        }
        return false;
    }

    /**
     * 收货地址详情
     */
    @PostMapping("/get")
    @ApiOperation("收货地址详情")
    public Admin adminGet(Long adminId,String xxl_sso_sessionid){
        return adminSerview.adminGet(adminId,xxl_sso_sessionid);
    }

    /**
     * 获取默认收货地址
     */
    @ApiOperation("获取默认地址")
    @GetMapping("/priority")
    public boolean priorityGet(Long adminId, String xxl_sso_sessionid){
        return  adminSerview.truePriority(adminId,xxl_sso_sessionid);
    }

    /**
     * 获取收货地址列表
     */
    @ApiOperation("获取收货地址列表")
    @GetMapping("/get")
    public List<Admin>  getListAdmin(){
        return new ArrayList<>();
    }
}
